package com.luoying.itew.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by octopus on 17/7/12.
 */

public class MountainLogUtils {
    private static String logid = "-1";
    private static List logname = new ArrayList();
    private static List logtime = new ArrayList();
    private static List logcontent = new ArrayList();
    private static List loguseid = new ArrayList();

    private static boolean nextpage = false;
    public static boolean getnextpage(){
        return nextpage;
    }
    public static void setnextpage(boolean nextpage1){
        nextpage = nextpage1;
    }

    private static boolean havingNextPage =false;
    private static boolean havingPreviousPage =false;
    private static String nextpageurl =null;
    private static String previouspageurl =null;

    public static String getLogid() {
        return logid;
    }

    public static void setLogid(String id) {
        logid = id;
    }

    public static void setLogContent(JSONObject jsonObject) throws Exception {
        JSONObject jsonObject1 = jsonObject.getJSONObject("resultEntity").getJSONObject("pagination");
        JSONArray recordArray = jsonObject1.getJSONArray("records");
        if (nextpage){
            setNextPage(jsonObject1, recordArray);
        }
        else {
            logname.clear();
            logcontent.clear();
            logtime.clear();
            loguseid.clear();
            setNextPage(jsonObject1, recordArray);
        }
    }

    public static void setNextPage(JSONObject jsonObject,JSONArray jsonArray) throws JSONException {
        for(int i=0;i<jsonArray.length();i++) {
            JSONObject user1 = null;
            user1 = (JSONObject) jsonArray.get(i);
            logname.add(user1.getString("walkerName"));
            logtime.add(user1.getString("logCreateTime"));
            logcontent.add(user1.getString("logContent"));
            loguseid.add(user1.getString("walkerLogId"));
        }
        havingPreviousPage = false;
        havingNextPage=false;
        nextpageurl = null;
        previouspageurl = null;
        havingNextPage = jsonObject.getBoolean("havingNextPage");
        havingPreviousPage = jsonObject.getBoolean("havingPreviousPage");
        if (havingNextPage){
            nextpageurl = (jsonObject.getJSONObject("nextPage")).getString("url");
        }
        if (havingPreviousPage){
            previouspageurl = (jsonObject.getJSONObject("previousPage")).getString("url");
        }
    }

    public static String getlogname(int i){
        return logname.get(i).toString();
    }
    public static String getlogtime(int i){
        return logtime.get(i).toString();
    }
    public static String getlogcontent(int i){
        return logcontent.get(i).toString();
    }
    public static int getLognum(){
        return logname.size();
    }

    public static String getLoguseid(int i) {
        return loguseid.get(i).toString();
    }

    public static void setLoguseid(List loguseid) {
        MountainLogUtils.loguseid = loguseid;
    }

    public static String getNextpageurl() {
        return nextpageurl;
    }

    public static boolean isHavingNextPage() {
        return havingNextPage;
    }

    public static boolean isHavingPreviousPage() {
        return havingPreviousPage;
    }

    public static String getPreviouspageurl() {
        return previouspageurl;
    }
}
